package com.hdfs.client.config;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import java.net.URI;

@org.springframework.context.annotation.Configuration
public class HDFSConfig {
    @Autowired
    private HDFSProperties hdfsProperties;
    /**
     * 获取HDFS配置信息
     * @return
     */
    public Configuration getConfiguration() {
        Configuration configuration = new Configuration();
        configuration.set("fs.defaultFS", hdfsProperties.getHdfsPath());
        return configuration;
    }

    @Bean
    public FileSystem getFileSystem () throws Exception {
        FileSystem fileSystem = FileSystem.get(new URI(hdfsProperties.getHdfsPath()), getConfiguration(), hdfsProperties.getHdfsName());
        return fileSystem;
    }
}
